package com.example.zhujiemian;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;

import androidx.appcompat.app.AppCompatActivity;

public class Setting extends AppCompatActivity {
    private Switch mswitchAdmin;
    private Button mbuttonAddStudent;
    private Button mbuttonAddCourse;
    private Button mChangPassword;
    private Button mbuttonLogout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting);
        mswitchAdmin=findViewById(R.id.switchAdmin);
        mbuttonAddStudent=findViewById(R.id.buttonAddStudent);
        mbuttonAddCourse=findViewById(R.id.buttonAddCourse);
        mChangPassword=findViewById(R.id.ChangPassword);
        mbuttonLogout=findViewById(R.id.buttonLogout);

        boolean isAdminMode = false;
        mbuttonAddStudent.setVisibility(isAdminMode ? View.VISIBLE : View.GONE);
        mbuttonAddCourse.setVisibility(isAdminMode ? View.VISIBLE : View.GONE);

        mswitchAdmin.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mbuttonAddStudent.setVisibility(isChecked ? View.VISIBLE : View.GONE);
                mbuttonAddCourse.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        // 跳转到添加学生的界面
        mbuttonAddStudent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mbuttonAddStudent.setVisibility(View.VISIBLE);
                Intent intent=new Intent(Setting.this, AddStudent.class);
                startActivity(intent);
            }
        });
        // 设置添加课程按钮的点击事件
        mbuttonAddCourse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到添加课程的界面
                mbuttonAddCourse.setVisibility(View.VISIBLE);
                Intent intent=new Intent(Setting.this, AddCourse.class);
                startActivity(intent);
            }
        });
        /*跳转到修改密码界面*/
        mChangPassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mChangPassword.setVisibility(View.VISIBLE);
                Intent intent=new Intent(Setting.this, ChangePassWord.class);
                startActivity(intent);
            }
        });
        /*退出登录，挂登录界面*/
        mbuttonLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mChangPassword.setVisibility(View.VISIBLE);
                Intent intent=new Intent(Setting.this, LoginActivity.class);
                startActivity(intent);
            }
        });
    }
}